﻿using System;
using System.Collections.Generic;

namespace RxjhServer
{
	public class DropClass
	{
		private int _FLD_NPC;

		private int _FLD_LEVEL1;

		private int _FLD_LEVEL2;

		private int _FLD_PID;

		private int _FLD_PP;

		public int FLD_MAGICNew0;

		public int FLD_MAGICNew1;

		public int FLD_MAGICNew2;

		public int FLD_MAGICNew3;

		public int FLD_MAGICNew4;

		private int _FLD_NJ;

		private int _FLD_MAGIC0;

		private int _FLD_MAGIC1;

		private int _FLD_MAGIC2;

		private int _FLD_MAGIC3;

		private int _FLD_MAGIC4;

		private string _FLD_NAME;

		private int _是否提示;

		private int _需要金符;

		public static object AsyncLock = new object();

		public static object AsyngLock = new object();

		public static object AsynbLock = new object();

		public int FLD_NPC
		{
			get
			{
				return this._FLD_NPC;
			}
			set
			{
				this._FLD_NPC = value;
			}
		}

		public int FLD_LEVEL1
		{
			get
			{
				return this._FLD_LEVEL1;
			}
			set
			{
				this._FLD_LEVEL1 = value;
			}
		}

		public int FLD_LEVEL2
		{
			get
			{
				return this._FLD_LEVEL2;
			}
			set
			{
				this._FLD_LEVEL2 = value;
			}
		}

		public int FLD_PID
		{
			get
			{
				return this._FLD_PID;
			}
			set
			{
				this._FLD_PID = value;
			}
		}

		public int FLD_PP
		{
			get
			{
				return this._FLD_PP;
			}
			set
			{
				this._FLD_PP = value;
			}
		}

		public int FLD_NJ
		{
			get
			{
				return this._FLD_NJ;
			}
			set
			{
				this._FLD_NJ = value;
			}
		}

		public int FLD_MAGIC0
		{
			get
			{
				return this._FLD_MAGIC0;
			}
			set
			{
				this._FLD_MAGIC0 = value;
			}
		}

		public int FLD_MAGIC1
		{
			get
			{
				return this._FLD_MAGIC1;
			}
			set
			{
				this._FLD_MAGIC1 = value;
			}
		}

		public int FLD_MAGIC2
		{
			get
			{
				return this._FLD_MAGIC2;
			}
			set
			{
				this._FLD_MAGIC2 = value;
			}
		}

		public int FLD_MAGIC3
		{
			get
			{
				return this._FLD_MAGIC3;
			}
			set
			{
				this._FLD_MAGIC3 = value;
			}
		}

		public int FLD_MAGIC4
		{
			get
			{
				return this._FLD_MAGIC4;
			}
			set
			{
				this._FLD_MAGIC4 = value;
			}
		}

		public string FLD_NAME
		{
			get
			{
				return this._FLD_NAME;
			}
			set
			{
				this._FLD_NAME = value;
			}
		}

		public int 是否提示
		{
			get
			{
				return this._是否提示;
			}
			set
			{
				this._是否提示 = value;
			}
		}

		public int 需要金符
		{
			get
			{
				return this._需要金符;
			}
			set
			{
				this._需要金符 = value;
			}
		}

		public DropClass()
		{
			this.FLD_NPC = 0;
			this.FLD_LEVEL1 = 0;
			this.FLD_LEVEL2 = 0;
			this.FLD_PID = 0;
			this.FLD_PP = 0;
			this.FLD_MAGICNew0 = 0;
			this.FLD_MAGICNew1 = 0;
			this.FLD_MAGICNew2 = 0;
			this.FLD_MAGICNew3 = 0;
			this.FLD_MAGICNew4 = 0;
			this.FLD_NJ = 0;
			this.FLD_MAGIC0 = 0;
			this.FLD_MAGIC1 = 0;
			this.FLD_MAGIC2 = 0;
			this.FLD_MAGIC3 = 0;
			this.FLD_MAGIC4 = 0;
			this.FLD_NAME = "";
			this.需要金符 = 0;
		}

		public static List<DropClass> GetBossDrop(int leve, int npcid)
		{
			List<DropClass> result;
			using (new Lock(DropClass.AsynbLock, "Boss怪物掉落"))
			{
				List<DropClass> list = new List<DropClass>();
				List<DropClass> list2 = new List<DropClass>();
				Random random = new Random();
				int num = RNG.Next(0, 8000);
				foreach (DropClass current in World.BossDrop)
				{
					if (current.FLD_NPC != 0)
					{
						if (current.FLD_NPC == npcid && current.FLD_PP > num)
						{
							list.Add(current);
						}
						else if (current.FLD_LEVEL1 <= leve && current.FLD_LEVEL2 >= leve && current.FLD_PP >= num)
						{
							list.Add(current);
						}
					}
					else if (current.FLD_LEVEL1 <= leve && current.FLD_LEVEL2 >= leve && current.FLD_PP >= num)
					{
						list.Add(current);
					}
				}
				if (list.Count == 0)
				{
					result = null;
				}
				else
				{
					int num2 = random.Next(1, 4);
					int num3 = 0;
					foreach (DropClass arg_108_0 in list)
					{
						if (num3 >= num2)
						{
							break;
						}
						int index = random.Next(0, list.Count);
						list2.Add(list[index]);
						num3++;
					}
					if (list2.Count == 0)
					{
						result = null;
					}
					else
					{
						result = list2;
					}
				}
			}
			return result;
		}

		public static List<DropClass> GetGSDrop(int leve, int sl, int maxsl, int npcid)
		{
			List<DropClass> result;
			using (new Lock(DropClass.AsyngLock, "高手怪物掉落"))
			{
				List<DropClass> list = new List<DropClass>();
				List<DropClass> list2 = new List<DropClass>();
				Random random = new Random();
				int num = RNG.Next(0, 9000);
				foreach (DropClass current in World.Drop_GS)
				{
					if (current.FLD_NPC != 0)
					{
						if (current.FLD_NPC == npcid && current.FLD_PP > num)
						{
							list.Add(current);
						}
					}
					else if (current.FLD_LEVEL1 <= leve && current.FLD_LEVEL2 >= leve && current.FLD_PP >= num)
					{
						list.Add(current);
					}
				}
				if (list.Count == 0)
				{
					result = null;
				}
				else
				{
					int num2 = random.Next(sl, maxsl);
					int num3 = 0;
					foreach (DropClass arg_D9_0 in list)
					{
						if (num3 >= num2)
						{
							break;
						}
						int index = random.Next(0, list.Count);
						list2.Add(list[index]);
						num3++;
					}
					if (list2.Count == 0)
					{
						result = null;
					}
					else
					{
						result = list2;
					}
				}
			}
			return result;
		}

		public static DropClass GetRwDrop(Players play, int npcid)
		{
			List<DropClass> list = new List<DropClass>();
			Random random = new Random();
			int num = random.Next(0, 8000);
			if (play != null)
			{
				foreach (DropClass current in World.Drop)
				{
					if (current.FLD_NPC == npcid && current.FLD_PP > num && play.检查任务是否匹配(current.FLD_PID))
					{
						list.Add(current);
					}
				}
				if (list.Count > 0)
				{
					int index = random.Next(0, list.Count);
					return list[index];
				}
			}
			return null;
		}

		public static DropClass GetDrop(Players play, int leve, int npcid)
		{
			DropClass result;
			using (new Lock(DropClass.AsyncLock, "普通怪物掉落"))
			{
				List<DropClass> list = new List<DropClass>();
				Random random = new Random();
				int num = RNG.Next(0, 12000);
				foreach (DropClass current in World.Drop)
				{
					if (current.FLD_LEVEL1 <= leve && current.FLD_LEVEL2 >= leve && current.FLD_PP >= num)
					{
						if (current.需要金符 == 1)
						{
							if (play.检查金符())
							{
								list.Add(current);
							}
						}
						else if (current.需要金符 == 2)
						{
							if (play.检查银符())
							{
								list.Add(current);
							}
						}
						else if (current.需要金符 == 3)
						{
							if (play.检查公有药品())
							{
								list.Add(current);
							}
						}
						else
						{
							list.Add(current);
						}
					}
				}
				if (list.Count < 1)
				{
					result = null;
				}
				else
				{
					int index = random.Next(0, list.Count);
					result = list[index];
				}
			}
			return result;
		}
	}
}
